﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.MODEL.FoundationModel;
using MINERP.BLL.LeaderOperate;

namespace MINERP.LeaderOperate.Controller
{
    public class FrmBackPresenter
    {
        FrmSelectBackTch _view;
        BackOrderBLL _bll;
        public FrmBackPresenter(FrmSelectBackTch view)
        {
            _view = view;
            _bll = new BackOrderBLL();

            IniliView();
        }

        /// <summary>
        /// 初始化界面数据
        /// </summary>
        public void IniliView()
        {
            OrderInfo_Info oi = _bll.GetOrderinfoById(_view.OrderInfoId);
            _view.IniliateView(oi);
        }

        /// <summary>
        /// 返单
        /// </summary>
        internal void BackOrder()
        {
            int result = _bll.RebackWork(_view.OrderInfoId, _view.BackTechId, _view.OrderProductRemark);
            if (result == 0)
            {
                System.Windows.Forms.MessageBox.Show("返工成功！");
                _view.Close();
            }
            else if (result == -1)
            {
                System.Windows.Forms.MessageBox.Show("数据库异常，返工失败！");
            }
            else if (result == -2)
            {
                System.Windows.Forms.MessageBox.Show("不能返工到还未做的岗位!");
            }
            else if (result == -3)
            {
                System.Windows.Forms.MessageBox.Show("不能返工给还在操作的岗位!");
            }
            else if (result==-4)
            {
                System.Windows.Forms.MessageBox.Show("请选择正确的产品!");
            }      
        }
    }
}
